package cn.stylefeng.guns.modular.task.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.task.entity.TaskFeedback;
import cn.stylefeng.guns.modular.task.mapper.TaskFeedbackMapper;
import cn.stylefeng.guns.modular.task.model.params.TaskFeedbackParam;
import cn.stylefeng.guns.modular.task.model.result.TaskFeedbackResult;
import  cn.stylefeng.guns.modular.task.service.TaskFeedbackService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 作业反馈 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2021-06-25
 */
@Service
public class TaskFeedbackServiceImpl extends ServiceImpl<TaskFeedbackMapper, TaskFeedback> implements TaskFeedbackService {

    @Override
    public void add(TaskFeedbackParam param){
        TaskFeedback entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaskFeedbackParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskFeedbackParam param){
        TaskFeedback oldEntity = getOldEntity(param);
        TaskFeedback newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaskFeedbackResult findBySpec(TaskFeedbackParam param){
        return null;
    }

    @Override
    public List<TaskFeedbackResult> findListBySpec(TaskFeedbackParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskFeedbackParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskFeedbackParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaskFeedback getOldEntity(TaskFeedbackParam param) {
        return this.getById(getKey(param));
    }

    private TaskFeedback getEntity(TaskFeedbackParam param) {
        TaskFeedback entity = new TaskFeedback();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
